package com.igoal.service.dwr;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.igoal.dto.UserGoalEntryDTO;
import com.igoal.service.GoalEntryManager;
import com.igoal.service.SaveResult;

@Service("goalEntryManagerDWR")
public class GoalEntryManagerDWRImpl extends BaseDWRService implements GoalEntryManagerDWR {

	@Autowired
	private GoalEntryManager goalEntryManager;

	public void setGoalEntryManager(GoalEntryManager goalEntryManager) {
		this.goalEntryManager = goalEntryManager;
	}

	public int deleteGoalEntry(UserGoalEntryDTO dto) {
		if(!isLoginUser()){
			return SaveResult.FAIL;
		}
		String username = getUserInSession();
		return goalEntryManager.removeEntry(username, dto.getId());
	}

	public int saveEntry(UserGoalEntryDTO dto) {
		return goalEntryManager.saveEntry(dto);
	}

	public UserGoalEntryDTO getEntry(Long entryId) {
		return goalEntryManager.getEntry(entryId, null);
	}
}
